package com.mywork.mvpkodeinxml.base.ui.activity

import android.os.Bundle
import com.mywork.mvpkodeinxml.base.presenter.BasePresenter
import com.mywork.mvpkodeinxml.base.view.BaseView
import com.mywork.progressloading.ProgressLoading
import org.jetbrains.anko.toast
import org.kodein.di.KodeinAware
import org.kodein.di.android.closestKodein


abstract class BaseMvpActivity<T : BasePresenter<*>> : BaseActivity(), BaseView, KodeinAware {
    protected val parentKodein by closestKodein()

    abstract val mPresenter: T
    private val loadingDialog: ProgressLoading by lazy { ProgressLoading() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        loadingDialog.create(this)
        lifecycle.addObserver(mPresenter)
    }

    override fun showLoading() {
        loadingDialog.showLoading()
    }

    override fun hideLoading() {
        loadingDialog.hideLoading()
    }

    override fun showToast(msg: String) {
        toast(msg)
    }
}